{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{% load mytags %}

<script type="text/javascript">
  function check_script(){
    var test = $('input[name="script_type"]:checked').val();
    if (test=="undefined"||test==null){
        alert("请选择脚本类型!");
        return false;
    }
  }
</script>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>脚本列表</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a>
                            </li>
                            <li><a href="#">Config option 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    {% if log %}
                        <div class="alert alert-success text-center">{{ log }}</div>
                    {% endif %}
                    {% if error_log %}
                        <div class="alert alert-danger text-center">{{ error_log }}</div>
                    {% endif %}
                    <div class="row">
                        <div class="form-group col-lg-9">
                            <button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#new_script" data-whatever="@mdo">上传脚本</button>
                            <a href="{% url 'script_edit' %}?project={{project}}&action=new" class="btn btn-warning">新建脚本</a>
                        </div>
                        <div class="form-group mail-search pull-right col-lg-3">
                            <form id="checkform">
                                <div class="input-group">
                                        <input type="text" name="search_name" class="form-control input-sm">
                                        <input type="hidden" name="project"  value="{{ project }}" class="form-control input-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" form="checkform" formmethod="POST"  class="btn btn-sm btn-primary ">搜索</button>
                                        </div>
                                </div>
                            </form>
                        </div>
                    </div>


                    <div class="table-responsive">
                      <form>
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                                <th class="text-center">所属项目</th>
                                <th class="text-center">脚本用途</th>
                                <th class="text-center">脚本名称</th>
                                <th class="text-center">脚本类型</th>
{#                                <th class="text-center">脚本参数</th>#}
                                <th class="text-center">创建时间</th>
                                <th class="text-center">修改时间</th>
                                <th class="text-center">修改人</th>
                                <th class="text-center">管理</th>
                            </thead>
                            <tbody>
                                {% for num in menu %}
                                    <tr class="text-center">
                                        <td>{{num.project}}</td>
                                        <td>{{num.use_name}}</td>
                                        <td>{{num.script_name}}</td>
                                        <td>{{num.script_type}}</td>
{#                                        <td>{{num.input_args}}</td>#}
                                        <td>{{num.create_time|date:"Y-m-d H:i:s"}}</td>
                                        <td>{{num.modify_time|date:"Y-m-d H:i:s"}}</td>
                                        <td>{{num.operator}}</td>
                                        <td>
                                            <a href="{% url 'script_edit' %}?project={{num.project.mini_name}}&script_name={{num.script_name}}&action=edit" class="btn btn-xs btn-primary"><i class="icon-trash"></i> 编辑</a>
                                            <a href="{% url 'script_edit' %}?project={{num.project.mini_name}}&script_name={{num.script_name}}&action=del" class="btn btn-xs btn-danger" onclick="return confirm('确认删除吗？')"><i class="icon-trash"></i> 删除</a>
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                        <div class="col-sm-6">
                            <div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
                                Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
                            </div>
                        </div>
                        {% include 'paginator.html' %}
                      </form>
                    </div>

                    <div class="hr-line-dashed"></div>

                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="new_script">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel" align="center">上传脚本</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid" align="center">
           <form id="assetForm" method="post" class="form-horizontal"  enctype="multipart/form-data" onsubmit="return check_script();">
                    <div class="form-group"><label class="col-sm-2 control-label"> 脚本用途 <span class="red-fonts">*</span>: </label>
                        <div class="col-sm-10">
                            <input type="text" name="script_use" class="form-control">
                        </div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label"> 脚本名称 <span class="red-fonts">*</span>: </label>
                        <div class="col-sm-10">
                            <input type="text" name="script_name" class="form-control">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label"> 脚本类型 <span class="red-fonts">*</span> </label>
                        <div class="col-sm-8">
                              <input type="radio" value="py" name="script_type" >.py
                              <input type="radio" value="sh" name="script_type" >.sh
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label"> 脚本来源 <span class="red-fonts">*</span> </label>
                        <div class="col-sm-8">
                          <div class="form-group has-success">
                            <input type="file" name="up_file" class="btn btn-info" >
                            <span class="input-icon fui-check-inverted"></span>
                          </div>
                        </div>
                    </div>
            </form>
            
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success" form="assetForm" formmethod="post" formaction="{% url 'script_edit' %}?project={{project}}&action=add" >保存</button>
        <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

{%endblock%}
